<script setup lang="ts">
import type TabProp from "@/components/tab/type/TabProp.ts";

const emit = defineEmits(['close', 'click'])
const props = withDefaults(defineProps<TabProp>(), {
  active: false,
  interactive: false,
})

const close = () => {
  emit('close', props.code)
}
</script>

<template>
  <div class="tag-container" :class="[ { active, interactive }]">
    <slot></slot>
    <span class="text" @click="interactive && emit('click', code)">{{ text }}</span>
    <div class="close-div">
      <component v-if="interactive" class="close" @click="close" is="close"></component>
    </div>
  </div>
</template>

<style scoped>
.tag-container {
  font-weight: 500;
  font-size: 14px;
  width: fit-content;
  min-width: 50px;
  height: 30px;
  padding: 5px 5px 5px 5px;
  border: 1px solid #e9ecf2;
  border-radius: 2px;
  white-space: nowrap;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  box-shadow: 3px 1px 3px #f4f4f4;
  user-select: none;

  background: var(--color-default);
  color: var(--info-color);
}

.active {
  color: var(--primary-color);
}

.tag-container.interactive:hover {
  color: #5d87ff;
  background: #f0f7ff;
}

.text {
  flex-grow: 1;
  margin-left: 4px;
  margin-right: 4px;
}

.close-div {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.2em;
  height: 1.2em;
}
.close-div:hover {
  background-color: #e9ecf2;
}

.close {
  border-radius: 2px;
  font-size: 0.8em;
}

.close:hover {

  cursor: pointer;
}
</style>